<style>
    .tools-btn { padding: 5px 7px; border-radius: 12px; }

    
    .send-item-list li, .send-pet-list li { margin: 8px 0; }
    .send-item-list li .form-control, .send-pet-list li .form-control { margin-right: 2px; }
    .div_item_name{float: left;}
    .div_item_id{float: left;}
    form{margin-bottom: 300px;}
    .check_div{max-width: 500px; line-height: 25px;}
    .check_input{width: 100px;float: left;}
    #editor{
    	border: 1px solid #009F95;
    	width: 80%;
    	min-height: 200px;
    }
</style>
<link rel="stylesheet" type="text/css" href="/public/static/plugin/inputSearch/autocomplete.css" />
<link rel="stylesheet" type="text/css" href="/public/static/plugin/jQuerycxColor/css/jquery.cxcolor.css" />
<form method="post" action="/oss/?r=noticeSet/doAdd">
    <{include file='../common_params.tpl'}>

    <div class="box box-black">
        <div class="box-body">
            <table class="table table-bordered">
                <colgroup>
                    <col style="width: 20%;"></col>
                    <col style="width: 80%;"></col>
                </colgroup>
                
                <tr>
                    <th class="th-label">调用模板</th>
                    <td>
                        <select class="form-control" name="temple" id="temple" style="width: 150px;">
                            <option value="">请选择</option>
                            <{foreach from=$templetList item=item key=key}>
                        		<option value="<{$key}>"><{$item}></option>
                        	<{/foreach}>
                        </select>
                    </td>
                </tr>
                
                <tr class="type-info" for="1">
                    <th class="th-label">公告标题</th>
                    <td>
                        <input type="text" class="form-control inline" style="width: 150px;" name="title" id="title" />
                    </td>
                </tr>
                
                <tr class="type-info" for="1">
                    <th class="th-label">公告位置</th>
                    <td>
                        <input type="checkbox" class="form-control inline" name="type[]" value="1" checked="checked" />&nbsp;游戏内&nbsp;&nbsp;
                        <input type="checkbox" class="form-control inline" name="type[]" value="2" />&nbsp;选服页
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">公告内容</th>
                    <textarea style="display: none;" class="" name="content" id="content" rows="10" style="width: 60%;"></textarea>
                    <td>
                    	<div>
                    		  <input type="button" id="btn0" value="清除格式" />
                    		  <input type="button" id="btn1" value="加粗" />
                    		  <input type="button" id="btn2" value="斜体" />
                    		  <input type="button" id="btn3" value="下划线" />
                    		  <!--<input type="button" id="btn5" value="大小" />-->
                    		  <select id="btn5">
                    		  	<option value="">字体大小</option>
                    		  	<option value="25">25</option>
                    		  	<option value="26">26</option>
                    		  	<option value="27">27</option>
                    		  	<option value="28">28</option>
                    		  	<option value="29">29</option>
                    		  	<option value="30">30</option>
                    		  	<option value="31">31</option>
                    		  	<option value="32">32</option>
                    		  	<option value="33">33</option>
                    		  	<option value="34">34</option>
                    		  	<option value="35">35</option>
                    		  </select>
                    		  <input id="color_d" type="text" class="input_cxcolor" readonly value="#009900">
                    		  <input type="button" id="btn4" value="颜色" data-color = "#009900" />
                    	</div>
                    	<div id="editor">
      
                       </div>
                    </td>
                </tr>
<script src="/public/static/plugin/jQuerycxColor/js/jquery.cxcolor.min.js"></script>  
<script>
	var color=$("#color_d");

	var mycolor;
	color.bind("change",function(){
		//alert(this.value);		
		$("#btn4").attr('data-color',this.value);
	});

	mycolor=$("#color_d").cxColor();
</script>
<script type="text/javascript">
	
  	     var editor = document.getElementById('editor');
         editor.contentEditable = true;
       
        $("#btn1").click(function(){
        	var text = $("#editor").html();        	
        	var append = window.getSelection().toString();         	
        	append_l = '<b>'+append+'</b>';   	
        	str=text.replace(append,append_l);       	        	
        	$("#editor").html(str);
        });      
        
        
        $("#btn2").click(function(){
        	var text = $("#editor").html();        	
        	var append = window.getSelection().toString();       	
        	append_l = '<i>'+append+'</i>'       	    	
        	str=text.replace(append,append_l);       	
        	$("#editor").html(str);
        });
        
        $("#btn3").click(function(){
        	var text = $("#editor").html();        	
        	var append = window.getSelection().toString();       	
        	append_l = '<u>'+append+'</u>'       	    	
        	str=text.replace(append,append_l);       	
        	$("#editor").html(str);
        });
        
        $("#btn4").click(function(){
        	var text = $("#editor").html();        	
        	var append = window.getSelection().toString(); 
        	var data_color = $(this).attr('data-color');
        	append_l = '<font color="'+data_color+'">'+append+'</font>'       	
        	str=text.replace(append,append_l);       	
        	$("#editor").html(str);
        });
        
        $("#btn5").change(function(){
        	var text = $("#editor").html(); 
        	var size = $(this).val();
        	var append = window.getSelection().toString();       	
        	append_l = '<font size="'+size+'">'+append+'</font>'       	    	
        	str=text.replace(append,append_l);       	
        	$("#editor").html(str);
        });

        $("#btn0").click(function(){
        	var text = $("#editor").text();        	
        	console.log(text);
        	$("#editor").html(text);
        });
        
  </script>
                
                <!--<tr>
                    <th class="th-label">同步方式</th>
                    <td>
                        <select class="form-control inline" name="synchro_type" style="width: 150px;" id="synchro_type">
                        	<{foreach from=$synchroTypeList item=item key=key}>
                            <option value="<{$key}>"><{$item}></option>
                            <{/foreach}>
                        </select>
                        <input type="text" name="synchro_time" id="synchro_time" class="form-control inline time" style="display: none;" placeholder="自动同步时间" />
                    </td>
                    
                </tr>
                
                <tr id='server_tr' style="display: none;">
                	<th class="th-label">自动同步服务器</th>
                    <td>
                    	<div class="check_div">
                    		<{foreach from=$serverList item=item key=key}>
                    		<div class="check_input">
                    			<input name="server[]" type="checkbox" value="<{$key}>" />&nbsp;<{$item}>
                    		</div>
                    		<{/foreach}>
                       </div>
                    </td>
                </tr>-->
                
                <tr>
                    <th class="th-label">是否弹出</th>
                    <td>
                    	<select name="is_eject" class="form-control inline">
                            <{foreach from=$isEjectList item=item key=key}>
                            <option value="<{$key}>"><{$item}></option>
                            <{/foreach}>
                        </select>
                    </td>
                </tr>
                
                <!--<tr class="attach-info" for="1">
                    <th class="th-label">补偿奖励</th>
                    <td>
                        <ul class="nav send-item-list">
                            <li class="fli">
                                <div class="div_item_name"></div>
                                <div class="div_item_id"></div>
                                <input type="text" name="item_number[]" class="form-control inline" placeholder="数量" size="12" />
                                
                                <select name="is_bind[]" class="form-control inline">
                                	<{foreach from=$isBindList item=item key=key}>
                                    <option value="<{$key}>"><{$item}></option>
                                    <{/foreach}>
                                </select>

                                <div class="box-tools inline">
                                    <a href="javascript:;" class="tools-btn tools-btn-add badge bg-green"><i class="fa fa-plus"></i></a>
                                    <a href="javascript:;" class="tools-btn btn-del badge bg-red"><i class="fa fa-minus"></i></a>
                                </div>
                            </li>                           
                        </ul> 
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">可领取时间</th>
                    <td>
                    	<input type="text" name="receive_start_time" id="receive_start_time" class="form-control inline time_day" />-
                    	<input type="text" name="receive_end_time" id="receive_end_time" class="form-control inline time_day" />
                    </td>
                </tr>-->

                

            </table>
        </div>

        <div class="box-footer">
            <a href="javascript:history.go(-1);" class="btn btn-default">返回</a>
            
            <button type="submit" name="sub" class="btn btn-default pull-right">保存</button>

        </div>
    </div>
</form>


<script>
    $(function(){
    	$(".time").datetimepicker({
            format: 'yyyy-mm-dd hh:ii',
        });
        
        $(".time_day").datetimepicker({
            format: 'yyyy-mm-dd',
        });
        
        $("#synchro_type").change(function(){
        	var synchro_type = $(this).val();
        	if(synchro_type == 2){
        		$('#synchro_time').show();
        		$("#server_tr").show();
        	}else{
        		$("#synchro_time").hide();
        		$("#server_tr").hide();
        	}
        });
    	
    	
    	var cloneItem = $(".send-item-list li:first-child").clone();
    	
    	$(".tools-btn-add").live('click',function(){
    		var length = $(".send-item-list .fli").length;
        	if(length > 4){
        		layer.alert('发送的道具不能大于5种');
        		return false;
        	}
            var li = $(this).closest('li');
            var oneClone = cloneItem.clone();
            oneClone.insertAfter(li);
            oneClone.find('.sel-item-list').chosen();
            
            oneClone.find('.div_item_name').autocomplete({
            	placeholder: '道具名称',
		        hints: proposals,
		        width: 150,
		        height: 34,
		        showButton: false,
		        name:'item_name[]',
		        onSubmit: sub,
		        onBlur:blur,
		        search:search
	        });
            
            oneClone.find('.div_item_id').autocomplete({
            	placeholder: '道具ID',
            	hints: item_id,
            	width: 150,
            	height: 34,
            	showButton: false,
            	name:'item_id[]',
            	onSubmit: sub1,
            	onBlur:blur1,
            	search:search1
            });
        });


        $(".btn-del").live('click',function(){
            if(!window.confirm('是否要删除该条数据?')) return true;
            var li = $(this).closest('li'),
                ul = li.closest('ul');

            if(ul.children('li').length > 1){
                li.remove();
            }else{
                li.find('select, input').val('').change();
            }
        });
        
        
        var nameflag = true;
        var idflag = true;
        var numberflag = true;
        $('button[name="sub"]').click(function(){
        	var editor =  $('#editor').html();
        	//console.log(editor);
        	$('#content').val(editor);
        	//console.log($('#content').val());
        	//return false;
        	var title = $('input[name="title"]').val();
        	if(title == ''){
        		layer.alert('请填写公告标题', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
//      	var synchro_type = $("#synchro_type").val();
//      	if(synchro_type == 2){
//      		//自动同步的时候必须填写自动同步时间
//      		var synchro_time = $('#synchro_time').val();
//      		if(synchro_time == ''){
//      			layer.alert('请填写自动同步时间', {icon: 2, skin: 'layui-layer-molv'});
//          	    return false;
//      		}
//      		var arr = new Array();
//              $("input[name='server[]']:checkbox[checked]").each(function(i){
//                  arr[i] = $(this).val();
//              });
//              console.log(arr);console.log(arr.length);
//              if(arr.length <= 0){
//              	layer.alert('请填写自动同步的服务器', {icon: 2, skin: 'layui-layer-molv'});
//          	    return false;
//              }
//              
//      	}
        	
//      	$('input[name="item_name[]"]').each(function (i){
//      		if($(this).val() == ''){
//      			nameflag = false;
//      		}else{
//      			nameflag = true;
//      		}
//          });
//          
//          if(!nameflag){
//          	layer.alert('请填写道具名称', {icon: 2, skin: 'layui-layer-molv'});
//          	return false;
//          }
//
//          $('input[name="item_id[]"]').each(function (i){
//      		if($(this).val() == ''){
//      			idflag =  false;
//      		}else{
//      			idflag = true;
//      		}
//          });
//          
//          if(!idflag){
//          	layer.alert('请填写道具ID', {icon: 2, skin: 'layui-layer-molv'});
//          	return false;
//          }
//          
//          $('input[name="item_number[]"]').each(function (i){
//          	var max_overlap = $(this).attr('data-max');
//          	_sthis = $(this);
//		        var num = $(this).val();
//      		if($(this).val() == ''){
//      			numberflag = false;
//      		}else if(parseInt(num) > parseInt(max_overlap)){
//      			_sthis.val(max_overlap);
//      		}else{
//      			numberflag = true;
//      		}
//          });
//
//          if(!numberflag){
//          	layer.alert('请填写道具数量', {icon: 2, skin: 'layui-layer-molv'});
//          	return false;
//          }
//          
//          var receive_start_time = $("input[name='receive_start_time']").val();
//          var receive_end_time = $("input[name='receive_end_time']").val();
//          if(receive_start_time == '' || receive_end_time == ''){
//          	layer.alert('请填写领取时间', {icon: 2, skin: 'layui-layer-molv'});
//          	return false;
//          }
//          var oDate1 = new Date(receive_start_time);
//          var oDate2 = new Date(receive_end_time);
//          if(oDate1.getTime() > oDate2.getTime()){
//          	layer.alert('领取时间第二个必须大于第一个', {icon: 2, skin: 'layui-layer-molv'});
//          	return false;
//          }
            //return false;
        });
        
    });
    
    

</script>

<script>
	$("#temple").change(function(){
		var temple_id = $(this).val();
		if(temple_id == ''){
			$('#title').val('')
			$('#content').text('');
			return false;
		}
		var g = $('input[name="g"]').val();
	    var url = '?r=noticeTemplet/getTemplet&g='+g;
		$.ajax({
			type : 'POST',
    	    url : url,
		    data : {'temple_id':temple_id},
		    dataType :'JSON',
		    success : function(res){
			    if(res.status == 1){
			    	$('#title').val(res.data.title)
			    	$('#editor').text(res.data.content);			    	
			    	//$('#content').text(res.data.content);
			    }else{
					$('#title').val('')
					$('#editor').text('');
			        //$('#content').text('');
			    }
		    }
	    });
	});
</script>

<script src="/public/static/plugin/inputSearch/autocomplete.js"></script>
<script>

var proposals = {};
//根据道具名称搜索出道具id
var sub = function(val,input){
	getValue(val,input,1);
};

var blur =function(val,input){
	getValue(val,input,1);
};

var search = function(val){
	var data = selectGoods(val,1);
	return data;
};
$(document).ready(function(){
	$('.div_item_name').autocomplete({
		placeholder: '道具名称',
		hints: proposals,
		width: 150,
		height: 34,
		showButton: false,
		name:'item_name[]',
		onSubmit: sub,
		onBlur:blur,
		search:search
	});
});


function selectGoods(val,type){
	var g = $('input[name="g"]').val();
	var url = '?r=goods/autoComplete&g='+g;
	var json = '';
	$.ajax({
    	type : 'POST',
    	url : url,
    	async:false,
		data : {'val':val,'type':type},
		dataType :'JSON',
		success : function(res){
			if(res.status == 1){
				json = res.data;
			}else{
					
			}
		}
	});
	return json;
}

function getValue(val,input,type){
	var g = $('input[name="g"]').val();
	var url = '?r=goods/getValue&g='+g;
	$.ajax({
    	type : 'POST',
    	url : url,
		data : {'val':val,'type':type},
		dataType :'JSON',
		success : function(res){
			if(res.status == 1){
				if(type == 1){
					input.parent('div').parent('div').parent().find("input[name='item_id[]']").val(res.data.gid);
					input.parent('div').parent('div').parent().find("input[name='item_number[]']").attr('data-max',res.data.max_overlap);
					//input.parent('div').find(".proposal-list").empty();
				}else if(type == 2){
					input.parent('div').parent('div').parent().find("input[name='item_name[]']").val(res.data.name);
					input.parent('div').parent('div').parent().find("input[name='item_number[]']").attr('data-max',res.data.max_overlap);
					//input.parent('div').find(".proposal-list").empty();
				}
			}else{
					
			}
		}
	});
}

</script>


<script>
var item_id = {};
//根据道具id搜索出道具名称
var sub1 = function(val,input){
	getValue(val,input,2);
};

var blur1 =function(val,input){
	getValue(val,input,2);
};

var search1 = function(val){
	var data = selectGoods(val,2);
	return data;
};

$(document).ready(function(){
	$('.div_item_id').autocomplete({
		placeholder: '道具ID',
		hints: item_id,
		width: 150,
		height: 34,
		showButton: false,
		name:'item_id[]',
		onSubmit: sub1,
		onBlur:blur1,
		search:search1
	});
});


</script>

<script>
//	$("input[name='item_number[]']").live('blur',function(){
//		var max_overlap = $(this).attr('data-max');
//		var num = $(this).val();
//		var _this = $(this);
//		if( parseInt(num) > parseInt(max_overlap)){
//			layer.alert('该道具的最大数量是'+max_overlap, {icon: 2, skin: 'layui-layer-molv'});
//			_this.val(max_overlap);
//		}
//	});	
</script>

<script src="/public/static/plugin/ueditor/ueditor.config.js"></script>
<script src="/public/static/plugin/ueditor/ueditor.all.min.js"></script>
<script src="/public/static/plugin/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
//	var g = $('input[name="g"]').val();
//	var ue = UE.getEditor('content',{
//		serverUrl: "/oss/?r=ueditor/index&g="+g,
//      zIndex: 999,
//      initialFrameWidth: "100%", //初化宽度
//      initialFrameHeight: 300, //初化高度            
//      focus: false, //初始化时，是否让编辑器获得焦点true或false
//      maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',//允许的最大字符数 'fullscreen',
//      pasteplain:false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
//      autoHeightEnabled: true
//  });
</script>
